package _base0to1;

import java.util.ArrayList;
import java.util.List;

/**
 * 163. 缺失的区间
 */
public class No163 {
    private final List<List<Integer>> answer = new ArrayList<>();

    public List<List<Integer>> findMissingRanges(int[] nums, int lower, int upper) {
        int i = 0, n = nums.length;
        while (lower <= upper) {
            if (i < n && nums[i] == lower) {
                lower++;
                i++;
            } else {
                ArrayList<Integer> list = new ArrayList<>();
                list.add(lower);
                if (n > 0 && lower < nums[n - 1]) {
                    lower = nums[i];
                    list.add(lower - 1);
                    answer.add(list);
                } else {
                    list.add(upper);
                    answer.add(list);
                    break;
                }
            }
        }
        return answer;
    }
}
